package network;

import gui.LoginPanel;

import java.util.concurrent.ExecutionException;

import javax.swing.SwingWorker;

import data.LoginResponse;



public class LoginWorker extends SwingWorker<LoginResponse, Object> {

	private LoginPanel mLoginPanel = null;
	
	public LoginWorker(LoginPanel loginPanel) {
		mLoginPanel = loginPanel;
	}
	
	@Override
	protected LoginResponse doInBackground() throws Exception {
		return NetworkManager.getInstance().login(mLoginPanel.getLogin(),
				mLoginPanel.getPassword());
	}

	@Override
	protected void done() {
		LoginResponse status = null;
		try {
			status = get();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ExecutionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			mLoginPanel.loggedIn(status);
		}
		super.done();
	}
	
}